Is there a better alternative for the MySQL query below